package com.rd.student.jiaji.class3.sunguowei.day24;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class TestExecutor {

    private static final int CORE_POOL_SIZE=5;
    private static final int MAX_POOL_SIZE=10;
    private static final int QUEUE_CAPACITY=20;
    private static final long KEEP_ALIVE_TIME=1L;
    public static void main(String[] args) {
        //最常使用的是第三个构造器  也就是没有线程工厂的
        ThreadPoolExecutor executor=
                new ThreadPoolExecutor(
                        CORE_POOL_SIZE,
                        MAX_POOL_SIZE,
                        KEEP_ALIVE_TIME,
                        TimeUnit.SECONDS,
                        new ArrayBlockingQueue<>(QUEUE_CAPACITY),
                        new ThreadPoolExecutor.DiscardPolicy());
        for (int i = 0; i < 5; i++) {
            MyRunnable runnable=new MyRunnable();
            //相当于 new Thread(runnable).start()
            executor.execute(runnable);
        }
        //终止
        executor.shutdown();
        System.out.println("finished");
    }
}
